<?php
namespace controller;
require_once('model/login.php');
require_once('view/pageView.php');

class Control{
	
	private static $logOutButton = 'logOutButton';
	private static $logInButton = 'logInButton';
	
	/*
	 * @return string (HTML)
	 */
	public function getHTML(){

		$message = $this->checkControl();
		
		$html = new \view\PageView;
		return $html->checkIfLoggedIn($message);
	}
	/*
	 * @return string (message)
	 */
	private function checkControl(){
		
		$model = new \model\Login;
		
		if(isset($_POST[self::$logOutButton])){
			$message = $model->logOut();
		}else if(isset($_SESSION['loggedIn'])){
			$message = $model->checkSession();
		}else if(isset($_COOKIE['username'])&& isset($_COOKIE['password'])){
			$message = $model->checkCookies();
		}else if(isset($_POST[self::$logInButton])){
			$message = $model->tryLogIn();
		}else{
				$message = null;
		}
		return $message;
	}

}
 
